/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package com.adsi.graficos;

import com.adsi.logica.LogicaConsignacionLocal;
import com.adsi.modelo.Consignaciones;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.annotation.PostConstruct;
import javax.ejb.EJB;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.RequestScoped;
import org.primefaces.model.chart.MeterGaugeChartModel;

/**
 *
 * @author david
 */
@ManagedBean(name = "MeterGauge")
@RequestScoped
public class MeterGauge implements Serializable {

    @EJB
    private LogicaConsignacionLocal logicaConsignacion;

    private MeterGaugeChartModel meterGaugeModel;
    private List<Consignaciones> listaConsignaciones;

    @PostConstruct
    public void init() {
        createMeterGaugeModels();
    }
    
    public MeterGauge() {
    }

    public MeterGaugeChartModel getMeterGaugeModel() {
        return meterGaugeModel;
    }

    public void setMeterGaugeModel(MeterGaugeChartModel meterGaugeModel) {
        this.meterGaugeModel = meterGaugeModel;
    }

    public List<Consignaciones> getListaConsignaciones() {
        if(listaConsignaciones == null){
            try {
                listaConsignaciones = logicaConsignacion.consutar();
            } catch (Exception ex) {
                Logger.getLogger(MeterGauge.class.getName()).log(Level.SEVERE, null, ex);
            }
        }
        return listaConsignaciones;
    }

    public void setListaConsignaciones(List<Consignaciones> listaConsiganciones) {
        this.listaConsignaciones = listaConsiganciones;
    }

    public LogicaConsignacionLocal getLogicaConsignacion() {
        return logicaConsignacion;
    }

    public void setLogicaConsignacion(LogicaConsignacionLocal logicaConsignacion) {
        this.logicaConsignacion = logicaConsignacion;
    }

    private MeterGaugeChartModel initMeterGaugeModel() {

        List<Number> intervals = new ArrayList<Number>() {
            {
                add(20);
                add(40);
                add(60);
                add(80);
                add(100);
                add(120);
                add(140);
                add(160);
                add(180);
                add(200);
                add(220);
            }
        };
        return new MeterGaugeChartModel(getListaConsignaciones().size(), intervals);
    }

    private void createMeterGaugeModels() {
        System.out.println("Metodo Crear");
        /*
         meterGaugeModel = initMeterGaugeModel();
         meterGaugeModel.setTitle("MeterGauge Chart");
         meterGaugeModel.setGaugeLabel("km/h");
         */
        meterGaugeModel = initMeterGaugeModel();
        meterGaugeModel.setTitle("CONSIGNACIONES");
        //meterGaugeModel.setSeriesColors("66cc66,36F521,0DEFEF,F2F521,93b75f,E7E658,cc6666");
        meterGaugeModel.setGaugeLabel("Cantidad de Consignaciones");
        meterGaugeModel.setGaugeLabelPosition("bottom");
        meterGaugeModel.setShowTickLabels(true);
        meterGaugeModel.setLabelHeightAdjust(110);
        meterGaugeModel.setIntervalOuterRadius(90);

    }
}
